import { prop_static_name_prefix } from '../DataDefine/sourceData';

const diff_propTag = 'diff_prop';

export const prop_diff_prop_compare_type = `${prop_static_name_prefix}_compare_type`;

export type compare_type =
  | 'increase'
  | 'delete'
  | 'update'
  | 'static'
  | 'val_no_same';

export const keyWorld_compared_type = {
  increase: 'increase',
  delete: 'delete',
  update: 'update',
  static: 'static',
  valueNoSame: 'val_no_same',
};

/**
 * 基础 类型 比对 结果
 */
export class diff_prop {
  get [Symbol.toStringTag]() {
    return diff_propTag;
  }

  /**
   * 说明 比对后的类型
   * @param compare_type
   */
  constructor(compare_type: compare_type) {
    this[prop_diff_prop_compare_type] = compare_type;
    delete this.same_ind;
  }

  /**
   * 比对 说明
   */
  [prop_diff_prop_compare_type]: compare_type;

  /**
   * 仅适用于 数组 对比中 相似 索引值
   */
  same_ind?: number | string;
}

const diff_prop_staticTag = 'diff_prop_static';

export class diff_prop_static extends diff_prop {
  get [Symbol.toStringTag]() {
    return diff_prop_staticTag;
  }

  oldVal: any;

  constructor(oldVal: any) {
    super('static');
    this.oldVal = oldVal;
  }
}

const diff_prop_increaseTag = 'diff_prop_increase';

export class diff_prop_increase extends diff_prop {
  get [Symbol.toStringTag]() {
    return diff_prop_increaseTag;
  }

  newVal: any;

  constructor(newVal: any) {
    super('increase');

    this.newVal = newVal;
  }
}

const diff_prop_updateTag = 'diff_prop_update';

export class diff_prop_update extends diff_prop {
  get [Symbol.toStringTag]() {
    return diff_prop_updateTag;
  }

  oldVal: any;

  newVal: any;

  constructor(oldVal: any, newVal: any) {
    super('update');
    this.oldVal = oldVal;

    this.newVal = newVal;
  }
}

const diff_prop_deleteTag = 'diff_prop_delete';

export class diff_prop_delete extends diff_prop {
  get [Symbol.toStringTag]() {
    return diff_prop_deleteTag;
  }

  oldVal: any;

  constructor(oldVal: any) {
    super('delete');
    this.oldVal = oldVal;
  }
}

const diff_prop_val_no_sameTag = 'diff_prop_val_no_same';

export class diff_prop_val_no_same extends diff_prop {
  get [Symbol.toStringTag]() {
    return diff_prop_val_no_sameTag;
  }

  newVal: any;

  oldVal: any;

  constructor(oldVal: any, newVal: any) {
    super('val_no_same');
    this.oldVal = oldVal;
    this.newVal = newVal;
  }
}

// const diff_prop_type_errTag = 'diff_prop_type_err';

// export class diff_prop_type_err extends diff_prop {
//   get [Symbol.toStringTag]() {
//     return diff_prop_type_errTag;
//   }

//   newVal: any;

//   constructor(newVal: any) {
//     super('type_err');
//     this.newVal = newVal;
//   }
// }

export type quick_increase_or_delete = 'increase' | 'delete';

export type quick_increase_or_delete_instance =
  | diff_prop_increase
  | diff_prop_delete;

export const diff_prop_typeArr = {
  increase: diff_prop_increase,
  delete: diff_prop_delete,
  update: diff_prop_update,
  static: diff_prop_static,
  // typeErr: diff_prop_type_err,
  valueNoSame: diff_prop_val_no_same,
};
